package com.linghu.service;

import com.linghu.dao.DiningTableDAO;
import com.linghu.domain.DiningTable;
import com.sun.scenario.effect.impl.prism.PrImage;

import java.security.PrivateKey;
import java.util.List;

/**
 * @author 令狐荣豪
 * @version 1.0
 */
public class DiningTableService {//业务层
    //定义一个DiningTableDAO对象
    private DiningTableDAO diningTableDAO = new DiningTableDAO();

    //返回所有餐桌信息
    public List<DiningTable> list() {
        return diningTableDAO.queryMultiple("select id,state from diningTable;", DiningTable.class);
    }

    //根据id，查询对应的餐桌DiningTable对象
    //如果返回null，表示id对应的编号餐桌不存在
    public DiningTable getDiningTableById(int id) {
        return diningTableDAO.querySingle("select * from diningTable where id=?;", DiningTable.class, id);
    }

    //如果餐桌可以预定，调用方法，对其状态进行更新
    public boolean orderDiningTable(int id, String orderName, String orderTel) {
        int update =
                diningTableDAO.update("update diningTable set state='已经预定',orderName=?,orderTel=?", orderName, orderTel);

        return update > 0;

    }

    //需要提供一个更新餐桌状态的方法
    public boolean updateDiningTableState(int id, String state) {
        int update = diningTableDAO.update("update diningTable set state=? where id =?", state, id);
        return update > 0;
    }

    //提供一个方法，指定的餐桌设置为空闲状态
    public boolean updateDiningTableToFree(int id, String state) {
        int update = diningTableDAO.update("update diningTable set state=? ,orderName='',orderTel=''where id =?", state, id);
        return update > 0;
    }
}
